home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: jhewett@ix.netcom.com (Jerry Hewett)
- Newsgroups: comp.lang.c++
- Subject: Re: [Q]Normalized Random Nos.
- Date: Sat, 06 Apr 96 23:39:26 GMT
- Organization: Netcom
- Message-ID: <N.040696.153926.84@ix.netcom.com>
- References: <4k4gmh$7ol@fountain.mindlink.net>
- NNTP-Posting-Host: tem-ca1-12.ix.netcom.com
- X-NETCOM-Date: Sat Apr 06 5:39:54 PM CST 1996
- X-Newsreader: Quarterdeck Message Center [2.00]
-
- John (jswalby@mindlink.bc.ca) asks:
-
- > Does anybody out there have a C or C++ (msvc++) algorithm to generate
- > normalized random numbers (i.e. between 0 and 1) using the rand() function?
-
- Try this out -- it's a modified version of the sample program for rand() that
- comes with the MSVC online help:
-
- ----<snip>----
-
- /* RAND.C: This program seeds the random-number generator
- * with the time, then displays 10 random integers.
- */
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
-
- void main( void )
- {
- float result;
- int i;
-
- /* Seed the random-number generator with current time so that
- * the numbers will be different every time we run.
- */
-
- srand( (unsigned)time( NULL ) );
-
- /* Display 10 numbers. */
-
- for(i = 0;i < 10;i++ )
- {
- result = (float) rand ();
- printf ("%f\n",result / RAND_MAX);
- }
- }
-
- ----<snip>----
-
- Just guessing here, but do you need this for a fuzzy logic app?
-
- Jerry H.
-
-
-